package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.dto.DTResponseDto;
import com.hualude.roadsign.dto.JsonMsgDto;
import com.hualude.roadsign.dto.SignalMachineDto;
import com.hualude.roadsign.service.SignalMachineManageService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by smarteacup on 2017/7/25.
 */
@Controller
@RequestMapping("/rds_signalMachineManage")
public class SignalMachineManageController {


    @Resource
    private SignalMachineManageService signalMachineManageService;

    @RequestMapping(value = "/getSignalMachine4DT")
    @ResponseBody
    public DTResponseDto getSignalMachine4DT(DTRequestDto dtRequestDto,
                                             String actorIds,
                                             Integer orgId,
                                             Boolean audit,
                                             String startRoad,
                                             String endRoad,
                                             Integer alarmBinding) throws Exception {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = signalMachineManageService.getSignalMachine4DT(
                    dtRequestDto, actorIds, orgId, audit, startRoad, endRoad, alarmBinding);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/getStartRoad")
    @ResponseBody
    public JsonMsgDto getStartRoad(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineManageService.getStartRoad(roadName, actorId, orgId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getSignalMachine4APP")
    @ResponseBody
    public JsonMsgDto getSignalMachine4APP(String actorIds,
                                           Integer orgId,
                                           Integer mCount,
                                           Integer mSize,
                                           String city,
                                           String startRoad,
                                           String endRoad,
                                           String alarmType) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineManageService.getSignalMachine4APP(
                    actorIds, orgId, mCount, mSize, city, startRoad, endRoad, alarmType));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSignalMachineById")
    @ResponseBody
    public JsonMsgDto getSignalMachineById(Integer signalMachineById) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineManageService.getSignalMachineById(signalMachineById));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSectionByStartRoad")
    @ResponseBody
    public JsonMsgDto getSectionByStartRoad(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineManageService.getSectionByStartRoad(roadName, actorId, orgId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("deleteSignalMachine")
    @ResponseBody
    public JsonMsgDto deleteSignalMachine(String signalMachineIds) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineManageService.deleteSignalMachine(signalMachineIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("addSignalMachine")
    @ResponseBody
    public JsonMsgDto addSignalMachine(SignalMachineDto signalMachineDto) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineManageService.addSignalMachine(signalMachineDto));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("updateSignalMachine")
    @ResponseBody
    public JsonMsgDto updateSignalMachine(SignalMachineDto signalMachineDto) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineManageService.updateSignalMachine(signalMachineDto));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getCity4SignalMachine")
    @ResponseBody
    public JsonMsgDto getCity4SignalMachine(String actorIds, Integer orgId, Integer mCount, Integer mSize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineManageService.getCity4SignalMachine(actorIds, orgId, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getStartRoadByCity")
    @ResponseBody
    public JsonMsgDto getStartRoadByCity(String city, String actorIds, Integer orgId, Integer mCount, Integer mSize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineManageService.getStartRoadByCity(city, actorIds, orgId, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSectionByStartRoad4App")
    @ResponseBody
    public JsonMsgDto getSectionByStartRoad4App(String city, String roadName, String actorIds, Integer orgId, Integer mCount, Integer mSize) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineManageService.getSectionByStartRoad4App(city, roadName, actorIds, orgId, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSignalMachine4Map4App")
    @ResponseBody
    public JsonMsgDto getSignalMachine4Map4App(Integer orgId,
                                               String actorIds,
                                               double neLongitude,
                                               double neLatitude,
                                               double swLongitude,
                                               double swLatitude) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineManageService.getSignalMachine4Map4App
                    (orgId, actorIds, neLongitude, neLatitude, swLongitude, swLatitude));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/auditSignalMachine")
    @ResponseBody
    public JsonMsgDto auditSignalMachine(String signalMachineIds) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineManageService.auditSignalMachine(signalMachineIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    /**
     * @Description:
     * @Author: WYX.
     * @Date: 2018/5/1 17:42.
     */
    @ResponseBody
    @RequestMapping("/bindingDevice")
    public JsonMsgDto bindingDevice(String deviceId, Integer signalMachineId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineManageService.bindingDevice(deviceId, signalMachineId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @ResponseBody
    @RequestMapping("/unbindingDevice")
    public JsonMsgDto unbindingDevice(String deviceId, Integer signalMachineId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalMachineManageService.unbindingDevice(deviceId, signalMachineId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @ResponseBody
    @RequestMapping("/showAlarmHistory")
    public DTResponseDto showAlarmHistory(DTRequestDto dtRequestDto, String deviceId, Integer deviceType) {
        DTResponseDto dtResponseDto = null;
        try {
            dtResponseDto = signalMachineManageService.showAlarmHistory(dtRequestDto, deviceId, deviceType);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }
}
